<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of owners_controller
 *
 * @author wilson
 */
class Ownerscontroller extends AppController {

    //put your code here
    var $name = "Owners";

    function index($id, $proyect_id = null) {
        $this->set('id', $id);
        $this->set('proyect_id', $proyect_id);

        $this->set('owners', $this->Owner->find('all', array('conditions' => array('Owner.property_id' => $id), 'fields' => array('Owner.nombres', 'Owner.id', 'Owner.primer_apellido', 'Owner.segundo_apellido', 'Property.codigo', 'Owner.documento'))));
    }

    function owner_index($property_id) {
        $this->set('property_id', $property_id);
        $this->set('owners', $this->Owner->find('all', array('conditions' => array('Owner.property_id' => $property_id), 'fields' => array('Owner.nombres', 'Owner.id', 'Owner.primer_apellido', 'Owner.segundo_apellido', 'Property.codigo', 'Owner.documento'))));
    }

    function add($predio_id) {
        $this->set('est', $this->Session->read('estado'));
        if (!empty($this->data)) {
            $this->Owner->create();
            if ($this->Owner->saveAll($this->data)) {
                $this->Session->setFlash('Propietario Adicionado con éxito');
                $this->setAction('index', $predio_id);
            }
        } else {

            $this->data['Owner']['property_id'] = $predio_id;
        }
    }

    function add_quality_control($predio_id) {
        if (!empty($this->data)) {
            $this->Owner->create();
            if ($this->Owner->saveAll($this->data)) {
                $this->Session->setFlash('Propietario Adicionado con éxito');
                $this->redirect(array('controller' => 'owners', 'action' => 'owner_index', $predio_id));
            }
        } else {
            $this->data['Owner']['property_id'] = $predio_id;
        }
    }

    function edit($id) {
        $this->set('est', $this->Session->read('estado'));
        if (!empty($this->data)) {

            if ($this->Owner->save($this->data)) {
                $this->Session->setFlash('Propietario Editado con éxito');
                $this->setAction('index', $this->data['Owner']['property_id']);
            }
        } else {

            //$this->data=$this->Owner->findById($id);
            $this->data = $this->Owner->find("first", array("conditions" => array("Owner.id" => $id)));
        }
    }

}

?>
